/**     
 * @Title: PerformanceHandler.java   
 * @Package me.xxy.mq.demo.handler   
 * @Description: TODO
 * @author weiwei 
 * @date 2018年5月30日 下午5:43:09   
 * @version V1.0     
 */
package me.xxy.mq.demo.handler;

import me.xxy.mq.core.AbstractMessageHandler;
import me.xxy.mq.demo.MessageType;
import me.xxy.mq.demo.entity.DemoMessage;
import me.xxy.mq.demo.servlet.ConsoleWebSocket;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

/**
 * @ClassName: PerformanceHandler
 * @Description: TODO
 * @author weiwei
 * @date 2018年5月30日 下午5:43:09
 * 
 */
@Service
public class PerformanceHandler extends AbstractMessageHandler<DemoMessage> {

	private final static Log LOG = LogFactory.getLog(PerformanceHandler.class);

	public PerformanceHandler() {
		// 说明该handler监控的消息类型
		super(MessageType.PERFORMANCE_MESSAGE, DemoMessage.class);
	}

	/**
	 * 监听到消息后处理方法
	 */
	@Override
	public void handle(DemoMessage message) {
		// do handle
	}

	@Override
	public void handleFailed(DemoMessage obj) {
		StringBuilder sb = new StringBuilder();
		sb.append("msg:[").append(obj).append("], 超过失败次数，停止重试。");
		LOG.warn(sb.toString());
		ConsoleWebSocket.socket.sendMessage(sb.toString());
	}
}
